package hxy.dragon.compose.composables

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.Card
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.material.TextFieldDefaults
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Email
import androidx.compose.material.icons.filled.Lock
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.semantics.Role.Companion.Image
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import hxy.dragon.compose.R
import hxy.dragon.compose.ui.theme.Purple200
import hxy.dragon.compose.ui.theme.Purple500


@Preview(showBackground = true)
@Composable
fun LoginPage1() {
    Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {

        Card(
            modifier = Modifier.background(color = Color.White),
            elevation = 8.dp,
            shape = MaterialTheme.shapes.medium
        ) {
            Image(
                painter = painterResource(id = R.drawable.office),
                contentDescription = ""
            )

            Column(
                horizontalAlignment = Alignment.CenterHorizontally,
                verticalArrangement = Arrangement.Center,
                modifier = Modifier.padding(12.dp)
            ) {
                val emailText = remember {
                    mutableStateOf("")
                }
                val passwordText = remember {
                    mutableStateOf("")
                }
                val colors = TextFieldDefaults.outlinedTextFieldColors(
                    focusedBorderColor = Purple200,
                    unfocusedBorderColor = Purple500,
                    cursorColor = Purple500
                )



                Spacer(modifier = Modifier.height(16.dp))

                Text(
                    text = "电子邮件",
                    color = Purple200,
                    modifier = Modifier.fillMaxWidth(0.85f),
                    textAlign = TextAlign.Left
                )
                Spacer(modifier = Modifier.height(4.dp))
                MyTextField(
                    value = emailText.value,
                    colors = colors,
                    trailingtintIcon = Purple200,
                    trailingIcon = Icons.Default.Email,
                    painter = painterResource(id = R.drawable.email),
                    modifier = Modifier.fillMaxWidth(0.85f),
                    keyboardOptions = KeyboardOptions(
                        keyboardType = KeyboardType.Email
                    ),
                    onValueChange = {
                        emailText.value = it
                    }
                )
                Spacer(modifier = Modifier.height(8.dp))
                Text(
                    text = "密码",
                    color = Purple200,
                    modifier = Modifier.fillMaxWidth(0.85f),
                    textAlign = TextAlign.Left
                )
                Spacer(modifier = Modifier.height(4.dp))
                MyTextField(
                    value = passwordText.value,
                    colors = colors,
                    trailingtintIcon = Purple200,
                    trailingIcon = Icons.Default.Lock,
                    painter = painterResource(id = R.drawable.password),
                    modifier = Modifier.fillMaxWidth(0.85f),
                    keyboardOptions = KeyboardOptions(
                        keyboardType = KeyboardType.Password
                    ),
                    onValueChange = {
                        passwordText.value = it
                    }
                )
            }
        }
    }
}